package com.example.shi_02.customeview;

import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.widget.ListView;

import org.w3c.dom.ProcessingInstruction;

/**
 * Created by shi-02 on 2015/4/15.
 */
public class MyListView extends ListView {

    private final String TAG = "MyListView";

    private float downX;
    private float downY;

    private float moveX;
    private float moveY;

    private float upX;
    private float upY;

    public MyListView(Context context) {
        super(context);
    }

    public MyListView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public MyListView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {

        switch (ev.getAction()) {
            case MotionEvent.ACTION_DOWN:
                downX = ev.getRawX();
                downY = ev.getRawY();
                break;
            case MotionEvent.ACTION_MOVE:
                moveX = ev.getRawX();
                moveY = ev.getRawY();

                float disY = moveY - downY;
                if (disY < 10 && disY > -10) {
                    return true;
                }

                break;
            case MotionEvent.ACTION_UP:
                upX = ev.getRawX();
                upY = ev.getRawY();
                float y = upY - downX;
                if (y > -10 && y < 10) {
                    return true;
                }
                break;
        }

        return false;

    }
}
